Requires the CodeAChrome.DLL to run. You can find all files in the zipped archive of this issue.
'** Eddie - an LB Code Editor
'version 9
'added Liberty BASIC Keywords
'******************************************************
'CodeAChrome is copyright Alyce Watson, 2005.
'******************************************************
'CodeAChrome is free for commercial and non-commercial use.
'A credit to the author and a link to the website must be
'included in your program's documentation or readme file,
'and in any source code released to the public.
'Alyce Watson
'http://alycesrestaurant.com/
'******************************************************
'Use this DLL at your own risk. The author bears no responsibility
'for errors that may occur as the result of its use.
'******************************************************
'You may not reverse-engineer this DLL.
'You may not claim it as your own work.
'******************************************************
if val(Version$)<4.02 then
notice "For Liberty BASIC v4.02 and higher."
end
end if
[VariableSetup]
'#f will be the handle for opening files
'note that Version$ is a reserved variable name
EddieVersion$ = "9"
LibertyExe$ = "" 'path to Liberty.exe for running programs:
Freeform$ = "" 'path to Freeform
Runtime$ = "" 'path to runtime engine, run402.exe
Help$ = "" 'path to LB help
IniFile$ = "eddie9.ini" 'name of ini file for this version of Eddie
Curdir$ = DefaultDir$
text$ = "" 'variable to hold contents of texteditor
tempfile$ = DefaultDir$ + "\tempfile.bas" 'filename for writing a temp file to disk
savefile$ = "" 'filename for user saving file to disk
dim branch$(1000) 'array to hold branch labels
branch$(1) = "" 'first designation takes you to top of code
gosub [readIniFile]
[WindowSetup]
NOMAINWIN
WindowWidth = 600 : WindowHeight = 360
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup]
'menus
Menu #1, "&File", "&New", [new], "&Open", [open], "&Save", [save],_
|,"&Print", [print], "E&xit", [quit]
Menu #1, "&Edit", "&Undo",[undo],"Cu&t",[cut],"&Copy",[copy],"&Paste",[paste],|,_
"&Select All",[selectall]
Menu #1, "&Options", "&Syntax Color",[syntaxColor],"&Line Numbers",[lineNumbers]
Menu #1, "&Run","R&un", [run]
Menu #1, "&Tools", "&Go to Line", [gotoLine], "&Freeform", [freeform]
Menu #1, "&Help", "He&lp", [help], "&About", [about]
'buttons for a toolbar lookalike
button #1.new, "New",[new],UL, 0, 0, 45, 20
button #1.open, "Open",[open],UL, 45, 0, 45, 20
button #1.save, "Save",[save],UL, 90, 0, 45, 20
button #1.print, "Print",[print],UL, 135, 0, 45, 20
button #1.cut, "Cut",[cut],UL, 190, 0, 45, 20
button #1.copy, "Copy",[copy],UL, 235, 0, 45, 20
button #1.paste, "Paste",[paste],UL, 280, 0, 45, 20
button #1.run, "Run",[run],UL, 335, 0, 45, 20
button #1.help, "Help",[help],UL, 380, 0, 45, 20
stylebits #1.c, 0,_CBS_AUTOHSCROLL,0,0
combobox #1.c, branch$(),[chooseBranch],40,22,385,300
Open "Eddie - an LB Code Editor v." + EddieVersion$ for Window as #1
'trap the close event, if the user closes the
'window with the X button
#1 "trapclose [quit]"
#1 "resizehandler [resize]"
'set the font for the window and controls
#1 "font ms_sans_serif 10"
'select item in combobox
#1.c "selectindex 1"
open "CodeAChrome.dll" for dll as #r
hMain = hwnd(#1) 'handle of program window
calldll #r, "CreateCodeAChrome",_ 'code editing component
hMain as long,_ 'handle of program window
0 as long,_ 'x location of control
52 as long,_ 'y location of control
545 as long,_ 'width of control
250 as long,_ 'height of control
ret as long 'nonzero=success
if ret=0 then
notice "Error loading CodeAChrome. Program ended."
goto [quit]
end if
'activate resizehandler
calldll #user32, "MoveWindow",_
hMain as ulong, _ 'window handle
UpperLeftX as long,_ 'x location of window
UpperLeftY as long,_ 'y location of window
730 as long,_ 'desired width of window
590 as long,_ 'desired height of window
1 as boolean, ret as long
calldll #r, "SetContextMenuOn",_ 'right-click menu
0 as long,_ '1 = on, 0 = off
ret as void 'no return
calldll #r, "DoSetFocus",_ 'setfocus to codeachrome
ret as void 'no return
keys$ = " abs acs append as asc asn atn backgroundcolor$ beep binary bmpbutton bmpsave boolean button call "
keys$ = keys$ + " callback calldll case checkbox chr$ close cls colordialog combobox comboboxcolor$ commandline$ "
keys$ = keys$ + " confirm cos cursor data date$ dechex$ defaultdir$ dialog dialog_fs dialog_modal dialog_nf dialog_nf_modal "
keys$ = keys$ + " dialog_nf_fs dim displayheight displaywidth dll do drives$ dword dump else end eof err error err$ eval "
keys$ = keys$ + " eval$ exit exp field filedialog files fontdialog end for foregroundcolor$ function get gettrim global "
keys$ = keys$ + " gosub goto graphics graphics_fs graphics_fs_nsb graphics_nsb graphics_nf_nsb graphicbox groupbox hbmp "
keys$ = keys$ + " hexdec hwnd if inkey$ inp input input$ inputto$ instr int joy1x joy1y joy1z joy1button1 joy1button2 joy2x "
keys$ = keys$ + " joy2y joy2z joy2button1 joy2button2 kill left$ len let line listbox listboxcolor$ ll loadbmp locate loc "
keys$ = keys$ + " lof log long loop lower$ lprint lr maphandle max menu midipos mid$ min mkdir mod name next nomainwin "
keys$ = keys$ + " notice on open or out output platform$ playmidi playwave popupmenu print printerdialog printerfont$ prompt "
keys$ = keys$ + " ptr put radiobutton randomize read readjoystick redim rem restore resume return right$ rmdir rnd run "
keys$ = keys$ + " scan seek select short sin sort space$ spreadsheet sqr statictext str$ stopmidi struct stylebits sub "
keys$ = keys$ + " tab tan text textbox textboxcolor$ texteditor texteditorcolor$ text_fs text_nsb text_nsb_ins then time$ "
keys$ = keys$ + " timer titlebar trace trim$ txcount ul ulong unloadbmp until upper$ upperleftx upperlefty ur ushort using "
keys$ = keys$ + " val version$ void wait wend while window windowheight windowwidth window_nf winstring word word$ "
calldll #r, "SetKeyWords",_ 'replace keywords with string
keys$ as ptr,_ 'string containing keywords separated by spaces
ret as void 'no return
wait
[loop] Wait
[quit]
gosub [writeIniFile]
calldll #r, "DestroyCodeAChrome", ret as void
close #r : close #1 : END
[syntaxColor]
confirm "Use syntax colors?";ans$
if ans$ = "yes" then togglecol = 1 else togglecol = 0
calldll #r, "SetSyntaxColorOn",_ 'use syntax coloring
togglecol as long,_ '1 = on, 0 = off
ret as void 'no return
calldll #r, "DoSetFocus", re as void
wait
[lineNumbers]
confirm "Use line numbers?";ans$
if ans$ = "yes" then togglelines = 1 else togglelines = 0
calldll #r, "SetLineNumbersOn",_ 'use line numbers?
togglelines as long,_ '1 = on, 0 = off
ret as void 'no return
calldll #r, "DoSetFocus", re as void
wait
[new]
calldll #r, "DoNew",_ 'clear control
re as void
Wait
[open]
filedialog "Open",Curdir$ + "\*.bas",openfile$
if openfile$="" then wait
Curdir$ = SeparatePath$(openfile$)
calldll #r, "FileLoad",_ 'load file into codeachrome
openfile$ as ptr,_ 'name of file
re as void 'no return
gosub [fillBranch]
Wait
[save]
filedialog "Save As",Curdir$ + "\*.bas",savefile$
if savefile$="" then wait
'make sure that user had given the file a *bas extension
if right$(lower$(savefile$),4)<>".bas" then
savefile$=savefile$+".bas"
end if
Curdir$ = SeparatePath$(savefile$)
calldll #r, "FileSave",_ 'save contents to disk
file$ as ptr,_ 'save filename
re as void
Wait
[print]
calldll #r, "DoPrint",_ 'print contents of control
re as void
Wait
[help]
if Help$ = "" then gosub [FindHelpPath]
if Help$ = "" then wait
run "winhlp32 " + chr$(34) + Help$ + chr$(34)
Wait
[about]
notice "CodeAChrome code editing component is copyrighted by Alyce Watson, 2005."
Wait
[undo]
calldll #r, "EditUndo",_ 'undo last operation
re as void
wait
[cut]
calldll #r, "EditCutText",_ 'cut selected text to clipboard
re as void
wait
[copy]
calldll #r, "EditCopyText",_ 'copy selected text to clipboard
re as void
wait
[paste]
calldll #r, "EditPasteText",_ 'paste contents of clipboard at cursor
re as void
wait
[selectall]
calldll #r, "EditSelectAll",_ 'select all text in control
re as void
wait
[run]
if LibertyExe$ = "" then gosub [GetLibertyPath]
'if we can't find the path to Liberty BASIC
'we must abort the RUN operation
if LibertyExe$="" then wait
calldll #r, "FileSave",_ 'save contents to disk
tempfile$ as ptr,_ 'save filename
re as void
RUN LibertyExe$ + " " + chr$(34) + tempfile$ + chr$(34)
wait
[freeform]
if Freeform$ = "" then gosub [GetFreeformPath]
if Freeform$ = "" then wait
if Runtime$ = "" then gosub [GetRuntimePath]
if Runtime$="" then wait
run Runtime$ + " " + chr$(34) + Freeform$ + chr$(34)
wait
[GetLibertyPath]
filedialog "Find Liberty.exe",Curdir$ + "\*liberty*.exe",LibertyExe$
if LibertyExe$="" then
notice "Liberty.exe not found."
else
Curdir$ = SeparatePath$(LibertyExe$)
end if
RETURN
[GetRuntimePath]
filedialog "Find runtime engine",Curdir$ + "\*run*.exe",Runtime$
if Runtime$="" then
notice "Runtime engine not found."
else
Curdir$ = SeparatePath$(Runtime$)
end if
RETURN
[GetFreeformPath]
filedialog "Find Freeform",Curdir$ + "\*.tkn",Freeform$
if Freeform$="" then
notice "Freeform not found."
else
Curdir$ = SeparatePath$(Freeform$)
end if
RETURN
[GetHelpPath]
filedialog "Find Help",Curdir$ + "\*.hlp",Help$
if Help$="" then
notice "Help not found."
else
Curdir$ = SeparatePath$(Help$)
end if
RETURN
[readIniFile]
open IniFile$ for append as #f
lenFile = LOF(#f)
close #f
'if the length = 0, the file didn't exist, so get info from user
if lenFile=0 then
notice "To use Eddie successfully, you must set the path to Liberty.exe, Freeform, the runtime engine and the helpfile."
gosub [GetLibertyPath]
gosub [GetFreeformPath]
gosub [GetRuntimePath]
gosub [GetHelpPath]
else
'if the length is greater than 0, the file exists
'open it for input and read the first line into LibertyExe$
open IniFile$ for input as #f
line input #f, LibertyExe$
'read second line into Freeform$, only if end of file not reached
if eof(#f) = 0 then line input #f, Freeform$
'read third line into Runtime$, only if end of file not reached
if eof(#f) = 0 then line input #f, Runtime$
'read fourth line into Help$, only if end of file not reached
if eof(#f) = 0 then line input #f, Help$
close #f
end if
RETURN
[writeIniFile]
open IniFile$ for output as #f
print #f, LibertyExe$
print #f, Freeform$
print #f, Runtime$
print #f, Help$
close #f
RETURN
[fillBranch]
calldll #r, "GetNumberOfLines",_
rowcount as long 'returns number of lines, 0-indexed
rowcount = rowcount - 1 'because lines begin at 0
REDIM branch$(rowcount)
branch$(1)="" + space$(300) + "1"
'fill combobox with labels, functions and sub definitions
'pad with 300 spaces, then add line number
bx=2
For i=0 to rowcount
calldll #r, "GetLineTextLength",_ 'retrieve length of text in line
i as long,_ 'index of line
length as long 'returns length
line$ = space$(length + 1) 'create buffer to receive text
calldll #r, "GetLineText",_
i as long,_ 'index of line to retrieve
line$ as ptr,_ 'buffer for text
ret as void
If Left$(Trim$(line$),1)="[" Then
branch$(bx)=Trim$(line$) + space$(300) + str$(i)
bx=bx+1
End If
If Lower$(Word$(line$,1))="function" Then
branch$(bx)=Trim$(line$) + space$(300) + str$(i)
bx=bx+1
End If
If Lower$(Word$(line$,1))="sub" Then
branch$(bx)=Trim$(line$) + space$(300) + str$(i)
bx=bx+1
End If
Next
#1.c "reload"
#1.c "selectindex 1";
return
[chooseBranch]
'** CHOOSE BRANCH, SET EDITOR TO THAT POSITION
#1.c "selection? branchselect$"
'get the text at the end of the item
ln$ = right$(branchselect$, 6)
'get value of text, which will = linenumber
linenumber = val(ln$)
'now scroll texteditor so that line is at top
calldll #r, "SetTopLine",_ 'scroll this line to top
linenumber as long,_ 'index of line
re as void 'no return
Wait
[gotoLine]
calldll #r, "GetNumberOfLines",_
rowcount as long 'returns number of lines, 0-indexed
gotoLine=rowcount-1
msg$="Go to line? Max is ";gotoLine
prompt msg$;gotoLine
if gotoLine>rowcount-1 then gotoLine=rowcount
if gotoLine<0 then gotoLine=0
calldll #r, "SetTopLine",_ 'scroll this line to top
gotoLine as long,_ 'index of line
re as void 'no return
wait
Function SeparatePath$(f$)
fileindex=Len(f$)
filelength=Len(f$)
While Mid$(f$, fileindex,1)<>"\"
fileindex=fileindex-1
Wend
SeparatePath$=Left$(f$,fileindex)
End Function
[resize]
ww=WindowWidth : wh=WindowHeight-52
calldll #r, "MoveCodeAChrome",_ 'move/resize the control
0 as long,_ 'new x location
52 as long,_ 'new y location
ww as long,_ 'new width
wh as long,_ 'new height
re as void
#1 "refresh"
wait